import instance from '@/utils/axios.js'

export function apiGetComment ({ artid, offset, limit }) {
  return instance({
    url: '/app/v1_0/comments',
    method: 'GET',
    params: {
      type: 'a',
      source: artid,
      // 如果参数值为null，则默认请求时不会携带这个参数
      offset: offset,
      limit: limit
    }
  })
}

// 添加评论
export function apiAddComment ({ artid, content }) {
  return instance({
    url: '/app/v1_0/comments',
    method: 'post',
    data: {
      target: artid,
      content: content
    }
  })
}

// 渲染评论的回复
export function apiGetReply ({ comid, offset, limit }) {
  return instance({
    url: '/app/v1_0/comments',
    method: 'GET',
    params: {
      type: 'c',
      source: comid,
      // 如果参数值为null，则默认请求时不会携带这个参数
      offset: offset,
      limit: limit
    }
  })
}

// 添加评论的回复
export function apiAddReply ({ comid, content, artid }) {
  return instance({
    url: '/app/v1_0/comments',
    method: 'POST',
    data: {
      target: comid,
      content: content,
      art_id: artid
    }
  })
}

// 对评论进行点赞
export function givefiveComment (comid) {
  return instance({
    url: '/app/v1_0/comment/likings',
    method: 'post',
    data: {
      target: comid
    }
  })
}

// 对评论进行点赞
export function cancelgivefive (comid) {
  return instance({
    url: `/app/v1_0/comment/likings/${comid}`,
    method: 'DELETE'
  })
}
